package com.baidu.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.baidu.entity.PageResult;
import com.baidu.entity.QueryPageBean;
import com.baidu.entity.Result;
import com.baidu.pojo.Dietarylibrary;
import com.baidu.service.DietarylibraryService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/dietary")
public class DietarylibraryController {
    @Reference
    private DietarylibraryService dietarylibraryService;
    
    @RequestMapping("/findByPage")
    public PageResult findByPage(@RequestBody QueryPageBean queryPageBean){
        return dietarylibraryService.findByPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize(),queryPageBean.getQueryString());
    }

    @RequestMapping("/findDietarylibraryById")
    public Result findDietarylibraryById(Integer id){
        try{
            Dietarylibrary dietarylibrary=dietarylibraryService.findDietarylibraryById(id);
            return new Result(true,null,dietarylibrary);
        }catch(Exception e){
            e.printStackTrace();
            return new Result(false,"查询信息失败");
        }
    }

    @RequestMapping("/addDietarylibrary")
    public Result addDietarylibrary(@RequestBody Dietarylibrary Dietarylibrary){
        try{
            dietarylibraryService.addDietarylibrary(Dietarylibrary);
            return new Result(true, "添加成功");
        }catch(Exception e){
            e.printStackTrace();
            return new Result(false,"添加失败");
        }
    }

    @RequestMapping("/editDietarylibrary")
    public Result editDietarylibrary(@RequestBody Dietarylibrary Dietarylibrary){
        try{
            dietarylibraryService.editDietarylibrary(Dietarylibrary);
            return new Result(true, "修改成功");
        }catch(Exception e){
            e.printStackTrace();
            return new Result(false,"修改失败");
        }
    }

    @RequestMapping("/deleteDietarylibrary")
    public Result editDietarylibrary(Integer id){
        try{
            dietarylibraryService.deleteDietarylibraryById(id);
            return new Result(true, "删除成功");
        }catch(Exception e){
            e.printStackTrace();
            return new Result(false,"删除失败");
        }
    }
}
